<script type="text/javascript">  

function Cat_Standalone_Success(id){
    selected_cat = id;
    Load_Cat_List();
};

var selected_cat = '<?=set_value("category",$item["id_Categories"])?>';
var Load_Cat_List;

$(document).ready(function(){    
              
    // loads the categories into a json object
    Load_Cat_List = function(){ 
		 loading_queue++;
        $('#cat_select').html('<option value="">Loading categories...</option>');
        $.post("<?=site_url("/admin/categories/get_json_list")?>", {},
            function(data){
                Refresh_Cat_List(data);
				  loading_queue--;
            }, "json"
        );
    } 
    function Refresh_Cat_List(data){

        var selected = (selected_cat=='') ? ' selected="selected"' : '';
        var list = '';
        list += '<option value=""'+selected+'>--- select category ---</option>';  
        list += '<option value="" disabled="disabled"></option>';  
        for ( var i=0; i<data.length; i++ ){
            selected = (selected_cat==data[i].id) ? ' selected="selected"' : '';
            disabled = (data[i].children) ? ' disabled="disabled"' : '';
            list += '<option value="'+data[i].id+'"'+selected+disabled+'>' +data[i].title+ '</option>';
            if (data[i].children) {
                for ( var u in data[i].children ){
                    selected = (selected_cat==data[i].children[u].id) ? ' selected="selected"' : '';
                    list += '<option value="'+data[i].children[u].id+'"'+selected+'>&nbsp;&nbsp;-&nbsp;' +data[i].children[u].title+ '</option>';
                } 
            }
        }
        $('#cat_select').html(list);
        if (selected_cat!='') Load_Cat_Info();

    }     

    function Load_Cat_Info()
    {
        var id = $('#cat_select').val();  
        $("#cat_select option[value='']").remove();
        selected_cat = id;                                
        $.post("<?=site_url("admin/categories/view")?>", 
            {id:id},
            function(data){
                $('#cat_container').hide().html(data).fadeIn();
            }, "html"
        );
    }           

    $("#cat_select").change(function(){
        Load_Cat_Info();
    })  

    Load_Cat_List();


    $("#add_cat_trigger").click(function(){
        var url = '<?=site_url('admin/categories/add/standalone')?>';
        var new_window = window.open(url,"cat_manager","menubar=0,toolbar=0,location=0,status=0,toolbar=0,titlebar=0,scrollbars=1,width=840,height=500"); 
        new_window.focus();
        return false;
    })       

    $("#edit_cat_trigger").click(function(){
        var url = '<?=site_url('admin/categories/edit/')?>/'+selected_cat+'/standalone';
        var new_window = window.open(url,"cat_manager","menubar=0,toolbar=0,location=0,status=0,toolbar=0,titlebar=0,scrollbars=1,width=840,height=500"); 
        new_window.focus();
        return false;
    })
});
</script>


<div class="content_block">
    <h4>Product Name</h4>
    <input name="name" type="text" class="text_input" maxlength="250" value="<?=set_value('name', $item['Name_Products'])?>" />
</div>

<div class="content_block">
    <h4>Product Introduction</h4>
    <textarea name="introduction" class="tinymceEditor_no_paragraph"><?=set_value('introduction', $item['Introduction_Products'])?></textarea>
</div>

<div class="content_block">
    <h4>Product Description</h4>
    <textarea name="description" class="tinymceEditor_force_paragraph"><?=set_value('description', $item['Description_Products'])?></textarea>
</div>

<div class="content_block">
    <h4>Product Category</h4>
    <select id="cat_select" name="category" style="width:300px">
        <option> -------------------------------- </option>
    </select>
    <a href="#" id="add_cat_trigger" class="button">ADD NEW CATEGORY</a>
</div>

<div class="content_block" style="margin-top:-20px; width:100%">
    <div id="cat_container" class="preview">
    </div>
    <a href="#" id="edit_cat_trigger" class="button">EDIT CATEGORY</a>
</div>


